home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: BC4.5 won't compile it; GNU will [templates]
- Message-ID: <marnoldDoCrts.Dp2@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4ib0bk$16cg@usenetz1.news.prodigy.com>
- Date: Sat, 16 Mar 1996 09:03:28 GMT
- Sender: marnold@netcom2.netcom.com
-
- EWTE97A@prodigy.com (Gregory Gibson) writes:
-
- >//GNU compiles this and it runs. BC 4.5 does not compile it.
- >//And simple errors like (a<>b) instead of (a!=b) are ignored?
-
- What do you mean? I can't find these comparisons anywhere in the code you
- posted.
-
- >//What is wrong with BC 4.5?
-
- I think it is rather "what is wrong with GNU C++?" (read on).
-
- >// I APPRECIATE THE TIME INVESTMENT YOU MAKE!!!
-
- >// BC 4.5 does not seem to recognize the global 'pool'
-
-
- That's because you attempt use the global variable "pool" *before* it's
- definition is finished. I think Borland C++ is perfectly justified in
- telling you about a global variable that it does not yet know about.
-
- To start with, your declaration for pool looks like this...
-
- memman<film> pool;
-
- Seems simple enough.
-
- But, to fully know what type pool is, the compiler must instantiate the
- template memman<film>. memman<film>, in turn (using an internal typedef),
- instantiates list<film>, whose code refers to pool! And (for those who
- didn't try compiling the code) it's the references to pool inside list<>'s
- code that cause the error.
-
- Well, no wonder there's an error; this is a circular reference! pool depends
- on memman, which depends on list, which depends on pool. Seems to me that,
- as far as Borland C++ is concerned, pool does not exist when it's parsing
- the code for list, since it's doing so to find out just what pool is in the
- first place! pool probably hasn't been entered into the compiler's internal
- symbol table. So, when it sees the name pool in list<>'s code, it of course
- generates the error, "Undefined symbol pool...".
-
- If GNU compiles this file, I think it is being very "generous" with how it
- lets you use global variables in this way. It seems it treats variables as
- defined when it hasn't finished parsing their definitions. I wouldn't rely
- on this generousity if you want your code to compile elsewhere. I think
- Borland C++ is giving the correct result and your code indeed has an error.
-
- The problem with your code is conceptually similar to this...
-
- template <class T>
- class A
- {
- public:
- void SomeFunc()
- {
- global_a.SomeFunc(); // error!
- }
- };
-
- A<int> global_a;
-
-
- Which generates the error, "Undefined symbol global_a..." while trying to
- instantiate the variable "global_a". Again, this is due to the circular
- reference to global_a inside the code for A. global_a depends on A<>, which
- depends on global_a. It simply does not compute.
-
-
- Have you tried you code on other compilers?
-
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-